/*
 * 六瓜编程 2010-2020   @date: 2020-12-13 23:38:53
 * author : XiaoShengYang    [ motion_oal ]
 */
#include "motion_oal.h"

#include <lg_motor.h>
#include <lg_timer.h>

/* 默认参数 */
static struct trace_car_config g_trace_car_config = {
    .mode = TRACE,
    .dir = FRONT,
    .speed = 10,
    .sample_time_ms_motor = 10,
    .sample_time_ms_op_sensor = 10,
    .motor_callback = NULL,
    .op_sensor_callback = NULL,
};

lg_u32 trace_car_mnt_usr_callback(enum drv_offset offset,
                                  trace_car_callback fun)
{
    if (offset > DRV_OFFSET_MAX) {
        return -1;
    }

    if (offset == DRV_OFFSET_MOTOR) {
        g_trace_car_config.motor_callback = fun;
        return 0;
    }

    if (offset == DRV_OFFSET_OP_SENSOR) {
        g_trace_car_config.op_sensor_callback = fun;
        return 0;
    }
}

lg_bool trace_car_init(struct trace_car_config *car_config)
{
    lg_motor_wheel_init();
    /* 设置模式（向前）*/

    /* 方向（默认向前）*/
    lg_motor_wheel_set_dir(WHEEL_LEFT, g_trace_car_config.dir);
    lg_motor_wheel_set_dir(WHEEL_RIGHT, g_trace_car_config.dir);

    /* 速度（默认）*/
    lg_motor_wheel_set_speed(WHEEL_RIGHT, g_trace_car_config.speed);
    lg_motor_wheel_set_speed(WHEEL_LEFT, g_trace_car_config.speed);

    /* 选择模式（默认寻迹）*/
    trace_car_set_mode(g_trace_car_config.mode);

    /* 挂在回调函数 */
    trace_car_mnt_usr_callback(DRV_OFFSET_MOTOR,
                               g_trace_car_config.motor_callback);
    trace_car_mnt_usr_callback(DRV_OFFSET_OP_SENSOR,
                               g_trace_car_config.op_sensor_callback);

    /* 车轮回调间隔（默认）*/
    /* 查询传感器间隔（默认）*/
    lg_timer_set_callback(g_trace_car_config.motor_callback,
                          g_trace_car_config.sample_time_ms_motor);
    lg_timer_set_callback(g_trace_car_config.sample_time_ms_op_sensor,
                          g_trace_car_config.sample_time_ms_op_sensor);
}

lg_bool trace_car_deinit(struct trace_car_config *car_config)
{
}

lg_bool trace_car_set_config(lg_void)
{
}

lg_bool trace_car_start(lg_void)
{
}

lg_bool trace_car_pause(lg_void)
{
}

lg_bool trace_car_stop(lg_void)
{
}

lg_void trace_car_process(lg_void)
{
}